# -*- coding: utf-8 -*-

from hbcxx.cxx_format import *
from hbcxx.simcxx_exp import simcxx_convert_exp


def simcxx_create_enum(ir_enum):
    # For the enumeration, create the codes.
    enum_code = ['typedef enum {}'.format(ir_enum.name),
                 '{']
    for var_name in ir_enum.consts:
        enum_code.append(CXX_INDENT + '{} = {},'.format(
            var_name, simcxx_convert_exp(ir_enum.consts[var_name])))
    enum_code.append('} ' + '{};'.format(ir_enum.name))
    return '\n'.join(enum_code)


def simcxx_convert_enum(ir_enums):
    # Prepare the definitions.
    cxx_enum = []
    for ir_enum in ir_enums:
        # Convert each enum type.
        cxx_enum.append(simcxx_create_enum(ir_enum))
    return cxx_enum